﻿using _2112A_2_MES._XiangHe;
using _2112A_2_MES.XiangHes;
using _2112A_2_MES.XiangHes.WmSns;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace _2112A_2_MES.XiangHe.WmSns
{
    [ApiExplorerSettings(GroupName = "项鹤")]
    public class WmSnService:ApplicationService,IWmSnService
    {
        private readonly IRepository<Wmsns,int> _wmsnsrepository;
        public WmSnService(IRepository<Wmsns,int> wmsnsrepository)
        {
            _wmsnsrepository = wmsnsrepository;
        }

        /// <summary>
        /// 获取sn列表
        /// </summary>
        /// <returns></returns>
        [HttpGet,Route("/XiangHe/GetSnList")]
        public async Task<ReturnInfo<List<Wmsns>>> GetSnList(string? proCode, string? proName, string? piCode, int pageInde, int pageSize)
        {
            var snlist = await _wmsnsrepository.GetListAsync();
            if (!string.IsNullOrEmpty(proCode))
            {
                snlist = snlist.Where(x => x.ItemCode.Contains(proCode)).ToList();
            }
            if (!string.IsNullOrEmpty(proName))
            {
                snlist = snlist.Where(x => x.ItemName.Contains(proName)).ToList();
            }
            if (!string.IsNullOrEmpty(piCode))
            {
                snlist = snlist.Where(x => x.BatchCode.Contains(piCode)).ToList();
            }
            int totalCount=snlist.Count();
            snlist = snlist.Skip((pageInde - 1) * pageSize).Take(pageSize).ToList();
            if (snlist != null)
            {
                return new ReturnInfo<List<Wmsns>>(true, "0", snlist, totalCount);
            }
            return new ReturnInfo<List<Wmsns>>(true, "1", null, 0);
        }
    }
}
